#!/bin/bash

echo "========================================"
echo "        码将游戏打包工具"
echo "========================================"
echo

echo "正在检查Python环境..."
python3 --version
if [ $? -ne 0 ]; then
    echo "错误：未找到Python3环境"
    exit 1
fi

echo
echo "正在安装依赖..."
pip3 install -r requirements.txt

echo
echo "正在清理旧的构建文件..."
rm -rf dist build

echo
echo "正在打包游戏..."
pyinstaller build_config.spec

echo
if [ -f "dist/码将-密码学麻将/码将-密码学麻将" ]; then
    echo "打包成功！"
    echo "可执行文件位置：dist/码将-密码学麻将/"
    echo
    echo "是否立即运行游戏？(y/n)"
    read -r choice
    if [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then
        ./dist/码将-密码学麻将/码将-密码学麻将
    fi
else
    echo "打包失败！请检查错误信息。"
fi

echo
read -p "按回车键退出..." dummy 